package ws.jdbc.concurrent.driver.sqlserver

import static java.sql.ResultSet.*

/**
 * Test case of CResultSetScrollableReadOnly class methods.
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
class CResultSetScrollableReadOnlyTest extends ScrollableReadOnlyTest {

  /**
   * Run this before every test.
   */
  @Override
  void setUp() {
    super.setUp()

    def stmt = con.createStatement(TYPE_SCROLL_SENSITIVE, CONCUR_READ_ONLY)
//    stmt.setFetchSize(256)
    rs = stmt.executeQuery(sqlQuery)

    assertNotNull rs
    assertTrue rs instanceof CResultSetScrollableReadOnly
  }

  void testNull() {
    println "testNull()"
    def stmt = con.createStatement(TYPE_SCROLL_SENSITIVE, CONCUR_READ_ONLY)
    stmt.executeUpdate("INSERT INTO Table1 VALUES (null, null)")

    rs.close()

    rs = stmt.executeQuery(sqlQuery)

    rs.last()
    assertEquals 0, rs.getInt(1)
    assertTrue rs.wasNull()
    assertNull rs.getString(2)
    assertTrue rs.wasNull()

    rs.previous()
    assertTrue !rs.wasNull()

    stmt.close()
  }
}